import numpy as np
import matplotlib.pyplot as plt

def plot(ax, Zticks, Error, index_focus):

    x = Zticks
    y = np.abs(Error)

    plt.plot(x, y)

    nx = len(x)
    # 获取坐标轴的范围
   
    n_focus = index_focus
    n_max   = np.where(y == np.max(y))

    y_focus = y[n_focus]
    y_max   = y[n_max]

    plt.axhline(y_max,   c="r",linestyle = "--")
    plt.axvline(x[n_max],c="r",linestyle = "--")

    plt.scatter(x[n_focus], y_focus, c="r",s=10, alpha=0.8)
    plt.xlabel("z/$\mu$m")
    plt.ylabel("Error($\%$)")

    text0 = "Error_max=" + str(round(np.max(y),4)) + "%"
    text1 = "Error_focus=" + str(round(y_focus,4)) + "%" 
    

    plt.text(x[10],y_max*(0.8), text0, c = "b", fontsize=8, ha='left', va='center')
    plt.text(x[10],y_max*(0.7), text1, c = "b", fontsize=8, ha='left', va='center')
    